package com.laolang.gongda.bookshop.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import org.springframework.format.annotation.DateTimeFormat;

import com.laolang.gongda.bookshop.enums.HeadPicTypeEnum;
import com.laolang.gongda.bookshop.enums.SexEnum;

/**
 * 用户
 * 
 * @author 用户
 * @version 1.0
 *
 */
@Entity
@Table
public class User implements Serializable {

	private static final long serialVersionUID = 1L;
	
	public static final String HEAD_PIC_DEFAULT = "default";

	public User() {
		super();
	}

	public User(String phone, String email, String nickName, String passWord, String city, SexEnum sex, Date birthday, String blogUrl, String descSelf,
			String headPic, HeadPicTypeEnum headPicType, UserStatus userStatus) {
		super();
		this.phone = phone;
		this.email = email;
		this.nickName = nickName;
		this.passWord = passWord;
		this.city = city;
		this.sex = sex;
		this.birthday = birthday;
		this.blogUrl = blogUrl;
		this.descSelf = descSelf;
		this.headPic = headPic;
		this.headPicType = headPicType;
		this.userStatus = userStatus;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", phone=" + phone + ", email=" + email + ", nickName=" + nickName + ", passWord=" + passWord + ", city=" + city + ", sex="
				+ sex + ", birthday=" + birthday + ", blogUrl=" + blogUrl + ", descSelf=" + descSelf + ", headPic=" + headPic + ", headPicType=" + headPicType
				+ ", userStatus=" + userStatus + ", version=" + version + "]";
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getPassWord() {
		return passWord;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public SexEnum getSex() {
		return sex;
	}

	public void setSex(SexEnum sex) {
		this.sex = sex;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getBlogUrl() {
		return blogUrl;
	}

	public void setBlogUrl(String blogUrl) {
		this.blogUrl = blogUrl;
	}

	public String getDescSelf() {
		return descSelf;
	}

	public void setDescSelf(String descSelf) {
		this.descSelf = descSelf;
	}

	public String getHeadPic() {
		return headPic;
	}

	public void setHeadPic(String headPic) {
		this.headPic = headPic;
	}

	public HeadPicTypeEnum getHeadPicType() {
		return headPicType;
	}

	public void setHeadPicType(HeadPicTypeEnum headPicType) {
		this.headPicType = headPicType;
	}

	public UserStatus getUserStatus() {
		return userStatus;
	}

	public void setUserStatus(UserStatus userStatus) {
		this.userStatus = userStatus;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@Id
	@GeneratedValue
	private Integer id;

	/**
	 * 用户手机号码
	 */
	@Column(unique = true)
	private String phone;

	/**
	 * 用户邮箱地址，唯一
	 */
	@Column(unique = true)
	private String email;

	/**
	 * 用户昵称，唯一
	 */
	@Column(name = "nick_name", unique = true)
	private String nickName;

	/**
	 * 用户密码，未使用加密
	 */
	@Column(name = "password")
	private String passWord;

	/**
	 * 用户所在地市名称 <br />
	 * 
	 */
	private String city;

	/**
	 * 用户性别 <br />
	 * 男为：MAIL<br />
	 * 女为：FAMAIL <br />
	 * 
	 * @see com.laolang.gongda.bookstore.enums.SexEnum
	 */
	@Enumerated(EnumType.STRING)
	private SexEnum sex;

	/**
	 * 用户出生日期
	 */
	@Temporal(TemporalType.DATE)
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date birthday;

	/**
	 * 用户博客地址
	 */
	@Column(name = "blog_url")
	private String blogUrl;

	/**
	 * 个人介绍
	 */
	@Column(name = "desc_self")
	private String descSelf;

	/**
	 * 用户头像图片的名称 <br />
	 * 如果用户未上传头像图片，也未选择已提供头像，则显示默认头像
	 */
	@Column(name = "head_pic")
	private String headPic;

	@Column(name = "head_pic_type")
	@Enumerated(EnumType.STRING)
	private HeadPicTypeEnum headPicType;

	@OneToOne
	@JoinColumn(name = "user_status", referencedColumnName = "status_desc")
	private UserStatus userStatus;

	@Version
	private Integer version;

}
